<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui"
	xmlns:fn="http://java.sun.com/jsp/jstl/functions">
<h:body>
	<ui:composition template="/pages/protected/admin/template.xhtml">
		<ui:define name='templatemo_content'>
			<!-- Cabeçalho  -->
			<h2>
				Usuarios
				<h:form id="btnNovo">
					<p:commandButton value="Novo" icon="ui-icon-plus"
						onclick="dlgNovo.show();" type="button"
						actionListener="#{usuarioMB.doPrepararInserir}" />
				</h:form>
			</h2>

			<!-- Lista de Usuarios -->
			<h:form id="listaUsuarios">
				<p:dataTable id="tbUsuarios" widgetVar="tbUsuarios" var="usu"
					value="#{usuarioMB.usuarios}" paginator="true" rows="10"
					paginatorPosition="bottom"
					paginatorTemplate="{PageLinks} {RowsPerPageDropdown}"
					rowsPerPageTemplate="5,10,15"
					emptyMessage="Nenhum usuário foi encontrado.">

					<p:column headerText="Matricula" filterBy="#{usu.matricula}"
						filterMatchMode="contains">
						<h:outputText value="#{usu.matricula}" />
					</p:column>

					<p:column headerText="Nome" filterBy="#{usu.nome}"
						filterMatchMode="contains">
						<h:outputText value="#{usu.nome}" />
					</p:column>

					<p:column headerText="Curso" filterBy="#{usu.nome}"
						filterMatchMode="contains">
						<h:outputText value="#{usu.curso}" />
					</p:column>

					<p:column headerText="Email" filterBy="#{usu.nome}"
						filterMatchMode="contains">
						<h:outputText value="#{usu.email}" />
					</p:column>

					<!-- Botoes de Acoes -->
					<p:column style="width:4%">
						<p:commandButton id="btnEditar" icon="ui-icon-pencil"
							oncomplete="dlgEdit.show()" update=":editUsuario">
							<f:setPropertyActionListener value="#{usu}"
								target="#{usuarioMB.selectedUsuario}" />
						</p:commandButton>
						<p:tooltip for="btnEditar" value="Editar" showEffect="fade"
							hideEffect="fade" />

						<p:commandButton id="btnDeletar" icon="ui-icon-trash"
							title="Selecionar cliente" action="#{usuarioMB.doRemover(usu)}"
							update=":listaUsuarios">
						</p:commandButton>
						<p:tooltip for="btnDeletar" value="Deletar" showEffect="fade"
							hideEffect="fade" />
					</p:column>
				</p:dataTable>
			</h:form>

			<!-- Editar  -->
			<p:dialog id="editDialog" header="Edite Usuario" widgetVar="dlgEdit"
				modal="true" height="auto" resizable="false">
				<p:outputPanel>
					<h:form id="editUsuario">
						<p:messages />
						<h:panelGrid columns="1" style="text-align: center !important;">
							<p:graphicImage value="#{usuarioMB.imagem}" id="eimagem" cache="false" width="100px" height= "100px"/>
							<p:fileUpload style="display:inline-block; width:200px; max-width:200px;" sizeLimit="3145728" widgetVar="uploader" label="Escolher imagem..."  fileUploadListener="#{usuarioMB.fileUpload}" auto="true" allowTypes="/(\.|\/)(gif|jpe?g|png)$/"  update="eimagem" multiple="false"  customUI="false">
							</p:fileUpload>
							</h:panelGrid>
						<h:panelGrid id="editPanel" columns="2">
						
						
							<h:outputLabel for="eMatricula" value="Matricula: *" />
							<p:inputText id="eMatricula"
								value="#{usuarioMB.selectedUsuario.matricula}" required="true"
								label="Matricula">
								<f:validateLength minimum="2" />
							</p:inputText>

							<h:outputLabel for="ePerfil" value="Perfil: *" />
							<p:selectOneMenu id="ePerfil"
								value="#{usuarioMB.selectedUsuario.perfil}" required="true"
								label="Perfil">
								<f:selectItems value="#{usuarioMB.perfis}" />
							</p:selectOneMenu>

							<h:outputLabel for="eNome" value="Nome: *" />
							<p:inputText id="eNome" value="#{usuarioMB.selectedUsuario.nome}"
								required="true" label="Nome">
								<f:validateLength minimum="2" />
							</p:inputText>

							<h:outputLabel for="eLogin" value="Login: *" />
							<p:inputText id="eLogin"
								value="#{usuarioMB.selectedUsuario.login}" required="true"
								label="Login">
								<f:validateLength minimum="2" />
							</p:inputText>

							<h:outputLabel for="eSenha" value="Senha: *" />
							<p:inputText id="eSenha"
								value="#{usuarioMB.selectedUsuario.senha}" label="Senha"
								required="true" />

							<h:outputLabel for="eCurso" value="Curso: " />
							<p:inputText id="eCurso"
								value="#{usuarioMB.selectedUsuario.curso}" label="curso">

							</p:inputText>

							<h:outputLabel for="eEmail" value="Email: " />
							<p:inputText id="eEmail"
								value="#{usuarioMB.selectedUsuario.email}" label="email">
								<f:validateLength minimum="2" />
							</p:inputText>

						</h:panelGrid>
							<p:commandButton value="Salvar" icon="ui-icon-check"
								update=":editUsuario :listaUsuarios"
								actionListener="#{usuarioMB.doAlterar}" />
							<p:button value="Cancelar" icon="ui-icon-closethick"
								immediate="true" update=":editUsuario :listaUsuarios"
								process="@this" oncomplete="dlgEdit.hide()" />
					</h:form>
				</p:outputPanel>
			</p:dialog>


			<!-- Novo  -->
			<p:dialog id="novoDialog" header="Novo Usuario" widgetVar="dlgNovo"
				modal="true" height="auto" resizable="false">
				<h:form id="novoUsuario">
					<p:messages />
					<h:panelGrid columns="1" style="text-align: center !important;">
						<p:graphicImage value="#{usuarioMB.imagem}" id="imagem" cache="false" width="100px" height= "100px"/>
						<p:fileUpload style="display:inline-block; width:200px; max-width:200px;" sizeLimit="3145728" widgetVar="uploader" label="Escolher imagem..."  fileUploadListener="#{usuarioMB.fileUploadI}" auto="true" allowTypes="/(\.|\/)(gif|jpe?g|png)$/"  update="imagem" multiple="false"  customUI="false">
						</p:fileUpload>
					</h:panelGrid>
					<h:panelGrid id="novoPanel" columns="2">
						<h:outputLabel for="nMatricula" value="Matricula: *" />
						<p:inputText id="nMatricula" value="#{usuarioMB.usu.matricula}"
							required="true" label="Matricula">
							<f:validateLength minimum="2" />
						</p:inputText>

						<h:outputLabel for="nPerfil" value="Perfil: *" />
						<p:selectOneMenu id="nPerfil" value="#{usuarioMB.usu.perfil}"
							required="true" label="Perfil">
							<f:selectItems value="#{usuarioMB.perfis}" />
						</p:selectOneMenu>

						<h:outputLabel for="nNome" value="Nome: *" />
						<p:inputText id="nNome" value="#{usuarioMB.usu.nome}"
							required="true" label="Nome">
							<f:validateLength minimum="2" />
						</p:inputText>

						<h:outputLabel for="nLogin" value="Login: *" />
						<p:inputText id="nLogin" value="#{usuarioMB.usu.login}"
							required="true" label="Login">
							<f:validateLength minimum="2" />
						</p:inputText>

						<h:outputLabel for="nSenha" value="Senha: *" />
						<p:inputText id="nSenha" value="#{usuarioMB.usu.senha}"
							label="Senha" required="true" />

						<h:outputLabel for="nCurso" value="Curso: " />
						<p:inputText id="nCurso" value="#{usuarioMB.usu.curso}"
							label="curso">

						</p:inputText>

						<h:outputLabel for="nEmail" value="Email: " />
						<p:inputText id="nEmail" value="#{usuarioMB.usu.email}"
							label="email">
							<f:validateLength minimum="2" />
						</p:inputText>

						<p:commandButton value="Salvar" icon="ui-icon-check"
							update=":novoUsuario :listaUsuarios"
							actionListener="#{usuarioMB.doInserir}" />
						<p:button value="Cancelar" icon="ui-icon-closethick"
							immediate="true" update=":novoUsuario :listaUsuarios"
							process="@this" oncomplete="dlgNovo.hide()" />
					</h:panelGrid>
				</h:form>
			</p:dialog>
		</ui:define>
	</ui:composition>
</h:body>
</html>